<?php
$GLOBALS['Md'] = "RHUSJW24";
$GLOBALS['Pd'] = "B";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD']."Modules/FJK46JDE/modconf.php");
MYTCONN();

		$QGroups = '';
		$QOffices = '';
		$QStatus = '';
		$QProcess = '';

		if ($_POST['SYSOffices'] != '') {

		$QStatus = ' AND tsv_Domain = '.$_POST['SYSOffices'];

		}
		if ($_POST['tsv_Flag'] != '') {

		$QOffices = ' AND tsv_Flag = '.$_POST['tsv_Flag'];

		}
		if ($_POST['SYSUserGroups'] != '') {

		$QGroups = ' AND tsv_Member = '.$_POST['SYSUserGroups'];

		}
		if ($_POST['tsv_Process'] != '') {

		$QProcess = ' AND tsv_Process = '.$_POST['tsv_Process'];

		}

		$GET = $GLOBALS['MYT']->db_array("SELECT
				tsv_ID AS COLID,
				smb_Name AS COL1,
				OriNombre AS COL2,
				tsv_DateStart AS COL3,
				tsv_DateEnd AS COL4,
				tsv_Observations AS COL5,
				PDESCRIPTION AS COL6,
				PID AS COL7,
				smb_ID,
				tsv_DateTime AS COL9
				FROM systemoffice.timeclock_staffoff
					INNER JOIN systemoffice.sys_process ON PID = tsv_Process
					INNER JOIN systemoffice.staff_members ON smb_ID = tsv_Member
					LEFT OUTER JOIN Origenes ON OriNumero = tsv_Domain
		WHERE tsv_Flag > 0 {$QStatus} {$QOffices} {$QGroups} {$QProcess}");
	$CARD = $GET[0];
	?>
<script charset="utf-8" type="text/javascript">

Ext.onReady(function(){

    var myData = [
	<?php
	for ($i=1;$i<=$CARD;$i++) {
	echo "[{$i},'{$GET[$i]['COLID']}','{$GET[$i]['COL1']}','".str_replace("MoneyOne","",$GET[$i]['COL2'])."','{$GET[$i]['COL9']}','{$GET[$i]['COL3']}','{$GET[$i]['COL4']}','{$GET[$i]['COL5']}','{$GET[$i]['COL6']}',{$GET[$i]['COL7']},{$GET[$i]['smb_ID']}]";
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
		{name: 'COLID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL9', type: 'string'},
               {name: 'COL3', type: 'string'},
               {name: 'COL4', type: 'string'},
               {name: 'COL5', type: 'string'},
               {name: 'COL6', type: 'string'},
               {name: 'COL7', type: 'int'},
               {name: 'smbID', type: 'int'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Numero", width: 50, sortable: true, locked:true, dataIndex: 'COLID'},
        {header: "Tipo de Evento", width: 200, sortable: true, locked:true,dataIndex: 'COL6'},
        {header: "Nome", width: 200, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Loja", width: 150, sortable: true, locked:true, dataIndex: 'COL2'},
        {header: "Registo", width: 100, sortable: true, dataIndex: 'COL9'},
        {header: "Inicio", width: 100, sortable: true, dataIndex: 'COL3'},
        {header: "Fim", width: 100, sortable: true, locked:true,dataIndex: 'COL4'},
        {header: "Observacoes", width: 250, sortable: true, locked:true,dataIndex: 'COL5'},
        {header: "", width: 1, dataIndex: 'COL7'},
        {header: "", width: 1, dataIndex: 'smbID'}
    ]);

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
	            ds: ds,
	            cm: colModel,
	            sm: selmode,
				listeners: {
	 				rowdblclick: function(ds, row) {
					var record = ds.getStore().getAt(row);
  					if (record.get('COL7')==390){
					idwindow('Dados do Evento','user_properties','user_form','<?php echo $MODURL;?>Lib/frm_staffmember.php?RSID='+record.get('smbID'),650,500);
					} else if (record.get('COL7')==392) {
					idwindow('Dados da Mudanca','user_properties','user_form','<?php echo $MODURL;?>Lib/frm_transfer.php?RSID='+record.get('COLID'),650,500);
					} else if (record.get('COL7')==397 || record.get('COL7')==398 || record.get('COL7')==399 || record.get('COL7')==401 || record.get('COL7')==402 || record.get('COL7')==403) {
					idwindow('Dados do Evento','user_properties','user_form','<?php echo $MODURL;?>Lib/frm_offs.php?RSID='+record.get('COLID'),650,500);
					}}
				},
	    height: 400,
        renderTo: 'UserList'
    });

});
</script>